home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libk.lha / Lib / KRB / DEST_TKT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-24  |  2.6 KB  |  119 lines

  1. /*
  2.  * $Source: /afs/athena.mit.edu/astaff/project/kerberos/src/lib/krb/RCS/dest_tkt.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology.
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  */
  11.  
  12. #ifndef lint
  13. static char *rcsid_dest_tkt_c =
  14. "$Id: dest_tkt.c,v 4.9 89/10/02 16:23:07 jtkohl Exp $";
  15. #endif /* lint */
  16.  
  17. #include <mit_copy.h>
  18. #include <stdio.h>
  19. #include <krb.h>
  20. /* #include <sys\file.h> */
  21. #include <sys\types.h>
  22. #include <sys\stat.h>
  23. #ifdef TKT_SHMEM
  24. #include <sys\param.h>
  25. #endif
  26. #include <errno.h>
  27. #include <fcntl.h>    /* MS-DOS */
  28.  
  29. extern int krb_debug;
  30. /*
  31.  * dest_tkt() is used to destroy the ticket store upon logout.
  32.  * If the ticket file does not exist, dest_tkt() returns RET_TKFIL.
  33.  * Otherwise the function returns RET_OK on success, KFAILURE on
  34.  * failure.
  35.  *
  36.  * The ticket file (TKT_FILE) is defined in "krb.h".
  37.  */
  38.  
  39. dest_tkt()
  40. {
  41. #ifdef IBMPC
  42.     extern int lock_tkt(tkt_header far *,int);
  43.     extern void unlock_tkt(tkt_header far *);
  44.     tkt_header far *hdr;
  45.     char far *ptr;
  46.     char *value;
  47.     unsigned segment,i;
  48.     
  49.     if ((hdr=tkt_ptr())==NULL) {
  50. #ifdef DEBUG
  51.         if (krb_debug)
  52.             printf("Ticket memory not reserved or"
  53.                 "corrupt environment variable\n");
  54. #endif
  55.         return RET_TKFIL;
  56.     }
  57.  
  58.     if (!lock_tkt(hdr,1))
  59.         return KFAILURE;
  60.     
  61.     hdr->eof_ptr=sizeof(tkt_header);        /* drop everything */
  62.     ptr=(char far *)hdr + hdr->eof_ptr;
  63.     /*    Nuke everything.    */
  64.     for (i=hdr->eof_ptr;i<hdr->buf_size;i++)
  65.         *ptr++='\0';
  66.     unlock_tkt(hdr);
  67.     return (KSUCCESS);
  68.  
  69. #else /* !IBMPC */
  70.     char *file = TKT_FILE;
  71.     int i,fd;
  72.     struct stat statb;
  73.     char buf[BUFSIZ];
  74. #ifdef TKT_SHMEM
  75.     char shmidname[MAXPATHLEN];
  76. #endif /* TKT_SHMEM */
  77.  
  78.     errno = 0;
  79.     if (stat(file,&statb) < 0)
  80.     goto out;
  81.  
  82.     if (!(statb.st_mode & S_IFREG)
  83. #ifdef notdef
  84.     || statb.st_mode & 077
  85. #endif
  86.     )
  87.     goto out;
  88.  
  89.     if ((fd = open(file, O_RDWR, 0)) < 0)
  90.     goto out;
  91.  
  92.     bzero(buf, BUFSIZ);
  93.  
  94.     for (i = 0; i < statb.st_size; i += BUFSIZ)
  95.     if (write(fd, buf, BUFSIZ) != BUFSIZ) {
  96.         (void) close(fd);
  97.         goto out;
  98.     }
  99.  
  100.     (void) close(fd);
  101.  
  102.     (void) unlink(file);
  103.  
  104. out:
  105.     if (errno == ENOENT) return RET_TKFIL;
  106.     else if (errno != 0) return KFAILURE;
  107. #ifdef TKT_SHMEM
  108.     /* 
  109.      * handle the shared memory case 
  110.      */
  111.     (void) strcpy(shmidname, file);
  112.     (void) strcat(shmidname, ".shm");
  113.     if ((i = krb_shm_dest(shmidname)) != KSUCCESS)
  114.     return(i);
  115. #endif /* TKT_SHMEM */
  116.     return(KSUCCESS);
  117. #endif    /* IBMPC */
  118. }
  119.